package com_.dxy_test_.class_this_;

/**
 * @Description 测试 Class.this.xxx 内部类调用外部类成员的写法
 * @Author dangxianyue
 * @Date 2024/1/5 16:58
 */
public class OuterClass {
    private int value = 10;
    private void print() {
        System.out.println("外部类方法：print-OuterClass");
    }

    // 内部类
    public class InnerClass {
        private int value = 20;
        private void print() {
            System.out.println("内部类方法-print-InnerClass");
        }

        public void printValues() {
            // 访问内部类的 value
            System.out.println("内部类属性: " + this.value);
            this.print();

            // 访问外部类的 value
            System.out.println("外部类属性: " + OuterClass.this.value);
            OuterClass.this.print();
        }
    }


    public static void main(String[] args) {
        OuterClass outer = new OuterClass();
        OuterClass.InnerClass inner = outer.new InnerClass();
        inner.printValues();
    }

}
